import actionTypes from '../actions/actionTypes'
import { Reducer } from 'redux'
import { loginReducersType } from '.'
import UserType from '../types/UserType'

const initialLoginStatus: loginReducersType = {
    displayName: '',
    isLogin: false,
    userID: -1,
    userType: UserType.DEVICEADMIN
}

export const loginReducers: Reducer = (state = initialLoginStatus, action) => {
    switch (action.type) {
        case actionTypes.LOGIN_SUCCESS:
            return {
                ...state,
                isLogin: true,
                displayName: action.displayName,
                userID: action.userID,
                userType: action.userType
            }
        case actionTypes.LOGIN_FAIL:
            return {
                ...state,
                isLogin: false,
                displayName: ''
            }
        default:
            return state
    }
}
